<template>
    <div align="center">
        <h2>登录</h2>
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td>用户名:</td>
                    <td><input type="text" v-model="pdata.uname"></td>
                </tr>
                <tr>
                    <td>密码:</td>
                    <td><input type="password" v-model="pdata.pwd"></td>
                </tr>
                <tr>
                    <td></td>
                    <td><input type="button" class="btn btn-primary" value="登录" @click="login"></td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">

import axios from "axios";
import { useRouter } from "vue-router";
import { ref, reactive, onMounted } from "vue";    
const router = useRouter();

let pdata: any = reactive({
    uname: "",
    pwd: "",
})

const login = () => {


    if (pdata.uname == "") {
        alert('请输入用户名!');
        return;
    }
    if (pdata.pwd == "") {
        alert('请输入密码!');
        return;
    }
    

    axios({
        url: '/api/Hotel/Login',
        method: 'get',
        params: pdata
    }).then((res) => {
        if (res.data==-1) {
            alert('用户名不存在!!');
            return;
        } else if(res.data==-2){
            alert('密码错误!!');
            return;
        }else{
            console.log(res.data); //登录成功，将用户信息保存到本地存储 
            alert('登录成功!!'); 
            router.push({ path: "ShowHouseView", query: { userInfo: res.data } })
            return;
        }

    })
}


</script>

<style scoped></style>